﻿//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Licensed under the MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////


#include "ImportTypesModeDlg.h"
#include "GbmpNew.h"
#include "ui_ImportTypesModeDlg.h"
#include "GmStyleSheetHelper.h"
#include "GnufWorkBench.h"
#include "GnufStyleSheets.h"
#include "GnufStyleSheetComposer.h"

#include "EnableCompileWarning_The_LAST_IncludeInCpp.h"

using namespace gfam;
using namespace gcmp;
namespace
{
    const std::wstring s_dlgTitle = GBMP_TR(L"构件类型导入行为");
}
ImportTypesModeDlg::ImportTypesModeDlg(gcmp::IDocument* pDoc, QWidget *parent) : gnuf::QtDialog(parent, Qt::FramelessWindowHint)
, m_ui(NEW_AS_OWNER_PTR(Ui::ImportTypesModeDlg))
, m_pDoc(pDoc)
,m_modeId(ModeId::Add)
{
    m_ui->setupUi(this);
    if (gnuf::WorkBench* wb = gnuf::WorkBench::get())
    {
        if (const gnuf::StyleSheetComposer* ssc = wb->styleSheetComposer())
        {
            const_cast<gnuf::StyleSheetComposer*>(ssc)->addStyleSheet(gnuf::StyleSheet::eToQDialog);
            const_cast<gnuf::StyleSheetComposer*>(ssc)->addStyleSheet(gnuf::StyleSheet::eToQWidget);
            const_cast<gnuf::StyleSheetComposer*>(ssc)->addStyleSheet(gnuf::StyleSheet::eToQLabel);
            const_cast<gnuf::StyleSheetComposer*>(ssc)->addStyleSheet(gnuf::StyleSheet::eToQListView);
            const_cast<gnuf::StyleSheetComposer*>(ssc)->addStyleSheet(gnuf::StyleSheet::eToQGroupBox);
            const_cast<gnuf::StyleSheetComposer*>(ssc)->addStyleSheet(gnuf::StyleSheet::eToQComboBox);
            const_cast<gnuf::StyleSheetComposer*>(ssc)->addStyleSheet(gnuf::StyleSheet::eToQPushButton);
            const_cast<gnuf::StyleSheetComposer*>(ssc)->addStyleSheet(gnuf::StyleSheet::eToQLineEdit);
            const_cast<gnuf::StyleSheetComposer*>(ssc)->addStyleSheet(gnuf::StyleSheet::eToQRadioButton);
            setStyleSheet(QString::fromStdString(ssc->toString()));
        }
    }
    else
    {
        GmStyleSheetHelper* pStyleSheetHelper = GmStyleSheetHelper::Instance();
        DBG_WARN_AND_RETURN_VOID_UNLESS(pStyleSheetHelper, L"pStyleSheetHelper指针为空", L"paramodel", L"2024-02-20");
        std::wstring styleSheetStr = pStyleSheetHelper->GetCurrentStyleData();
        setStyleSheet(QString::fromStdWString(styleSheetStr));
    }
    m_ui->gbmp_title->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
    m_ui->gbmp_title->setIconVisible(false);
    m_ui->gbmp_title->setMaxButtonVisible(false);
    m_ui->gbmp_title->setMinButtonVisible(false);
    m_ui->gbmp_title->setCloseButtonVisible(true);
    m_ui->gbmp_title->setTextVisible(true);
    m_ui->gbmp_title->setText(QString::fromStdWString(s_dlgTitle));
    this->setProperty("use_gbmp_title", true);
    setWindowTitle(QString::fromStdWString(s_dlgTitle));
    setMouseTracking(true);
    connect(m_ui->gbmp_title, &GmTitleBar::closeRequested, this, &ImportTypesModeDlg::reject);
    connect(m_ui->gbmp_title, &GmTitleBar::moveRequested, this, &ImportTypesModeDlg::onMoveRequested);
    connect(m_ui->cancelButton, SIGNAL(clicked()), this, SLOT(Cancel()));
    connect(m_ui->applyButton, SIGNAL(clicked()), this, SLOT(Apply()));
    connect(m_ui->addCheckBox, SIGNAL(clicked(bool)), this, SLOT(Add(bool)));
    connect(m_ui->replaceCheckBox, SIGNAL(clicked(bool)), this, SLOT(Replace(bool)));
    connect(m_ui->overrideCheckBox, SIGNAL(clicked(bool)), this, SLOT(Override(bool)));
    m_ui->gbmp_title->setFocus();
}

void ImportTypesModeDlg::onMoveRequested(const QPoint& cursorPos, const QPoint& offset)
{
    Q_UNUSED(cursorPos);
    move(pos() + offset);
}

void ImportTypesModeDlg::Cancel()
{
    this->reject();
}

void ImportTypesModeDlg::Apply()
{
    this->accept();
}

void ImportTypesModeDlg::Add(bool checked)
{
    if (checked)
    {
        m_modeId = ModeId::Add;
    }
}

void ImportTypesModeDlg::Replace(bool checked)
{
    if (checked)
    {
        m_modeId = ModeId::Repalce;
    }
}

void ImportTypesModeDlg::Override(bool checked)
{
    if (checked)
    {
        m_modeId = ModeId::Override;
    }
}
ModeId ImportTypesModeDlg::GetModeId()
{
    return m_modeId;
}

ImportTypesModeDlg::~ImportTypesModeDlg()
{
    m_pDoc = nullptr;
}

